<%
const kdaLines = () => {
  if (!it.playerStats) return []

  const puuids = it.targetMembers
  const items = puuids.map((puuid) => {
    let name
    if (it.queryStage.phase === 'champ-select') {
      name = it.summoner[puuid]?.data.gameName || '未知召唤师'
    } else {
      let selection = it.championSelections[puuid] || -1
      name = it.gameData.champions[selection]?.name || '未知英雄'
    }

    const {
      averageKda = 0,
      count = 0,
      winRate = 0
    } = it.playerStats.players[puuid]?.summary || {}
    return { puuid, name, averageKda, count, winRate }
  })
  .map(({ name, averageKda, count, winRate }) => `${name}：近${count}场KDA ${averageKda.toFixed(2)} 胜率 ${(winRate * 100).toFixed(0)}%`)

  return items
}
%>
<%= kdaLines().join('\n') %>
